package com.witmore.neutron.ai.web.apiv2.nls;

import com.jk.common.response.ResponseResult;
import com.witmore.neutron.ai.web.annotation.NoLoginRequired;
import com.witmore.neutron.ai.web.apiv2.nls.config.NlsProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * V2 NLS 语音服务
 * Author: 豆子高
 * Date: 2025/6/9 18:20
 */
@Slf4j
@RequestMapping("/v2/nls")
@RestController
public class NlsControllerV2 {


    @Autowired
    private NlsTokenClient nlsTokenClient;

    @Autowired
    private NlsProperties nlsProperties;


    /**
     * nls服务获取凭证
     */
    @NoLoginRequired
    @GetMapping("/getCredentials")
    public ResponseResult<Map<String, String>> getCredentials() {
        Map<String, String> credentials = new HashMap<>();
        credentials.put("appKey", nlsProperties.getAppKey());
        credentials.put("expireTime", String.valueOf(nlsTokenClient.getAccessToken().getExpireTime()));
        credentials.put("token", nlsTokenClient.getAccessToken().getToken());
        credentials.put("ttsUrl", nlsProperties.getEndpoint());
        return ResponseResult.success(credentials);
    }
}
